package Leetcode第一期;

public class 整数反转_7 {
    public int reverse(int x) {
        int rev=0;
        while (x!=0){
            int pop=x%10;
            x=x/10;
            //求余是为了获取低位，并压入栈
            if(rev>Integer.MAX_VALUE/10||(rev == Integer.MAX_VALUE / 10 && pop > 7))return 0;
            if(rev<Integer.MIN_VALUE/10||(rev == Integer.MIN_VALUE / 10 && pop < -8))return 0;
            rev=rev*10+pop;
        }
        return rev;
    }

}
